<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>消费审核</title>
<%@include file="../collect/meta.jsp"%>
<link rel="stylesheet" href="css/radius.css" type="text/css"></link>
<link rel="stylesheet" href="css/table.css" type="text/css"></link>
<link rel="stylesheet" href="css/btn-bottom.css" type="text/css"></link>
<script type="text/javascript" src="${ctx}/js/returnTop.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctx }/calender/WdatePicker.js"></script>
</head>
<body lang="zh-cn">
	<div class="wrapper">
		<c:import url="/collect/top.jsp"></c:import>
		<div class="main-container" id="main-container">
			<div class="main-container-inner">
				<c:import url="/collect/left.jsp"></c:import>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i>消费审核</li>
						</ul>
						<!-- .breadcrumb -->
					</div>
					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="alert alert-success">
									【${shopName }】今日销售额：
									<fmt:formatNumber value="${dayConsume }" pattern="#0.00"/>元
								</div>
								<div id="btn-bottom">
									会员手机号：
									<input type="text" id="mobile" placeholder="手机号"
										value="${consume.memberMobile }" />
									&nbsp;
									店铺：
									<select id="eaStore">
										<c:choose>
											<c:when test="${not empty shops }">
												<option value="0">全部</option>
											</c:when>
											<c:otherwise>
												<option value="0"></option>
											</c:otherwise>
										</c:choose>
										<c:forEach items="${shops }" var="shop">
											<option value="${shop.id }" <c:if test="${shop.id == consume.shopId}">selected='selected'</c:if>>
												${shop.name}
											</option>
										</c:forEach>
									</select>
									&nbsp;
									审核状态：
									<select id="examineFlag">
										<option value="-1" <c:if test="${consume.examineFlag == -1}">selected='selected'</c:if>>全部</option>
										<option value="0" <c:if test="${consume.examineFlag == 0}">selected='selected'</c:if>>等待审核</option>
										<option value="1" <c:if test="${consume.examineFlag == 1}">selected='selected'</c:if>>已经审核</option>
									</select>
									&nbsp;
									小票号：
									<input type="text" id="smallBanks" placeholder="小票号"
										value="${consume.smallBanks }" />
									&nbsp;
									时间范围：
									<input type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
										id="beginTime" style="width:186px;height:30px;" placeholder="开始时间"
										value="${consume.beginTime }" >
									-
									<input type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
										id="endTime" style="width:186px;height:30px;" placeholder="结束时间"
										value="${consume.endTime }" >
									<br />
									&nbsp;金额范围：
									<input type="text" id="minMoney" placeholder="最小金额"
										value="${consume.minMoney }" />
									-
									<input type="text" id="maxMoney" placeholder="最大金额"
										value="${consume.maxMoney }" />
									&nbsp;
									<input type="button" id="oneMemberBtn" class="btn btn-primary radius btn-sm" value="搜索">
								</div>
								<div id="btn-bottom">
									<input type="button" id="verifyConsumeBtn" class="btn btn-success radius btn-sm" value="一键审核">
									&nbsp;
									对账金额：
									<input type="text" id="verifyConsume" name="verifyConsumeMoney" placeholder="对账金额">
								</div>
								<table id="table_bug_report"
									class="table table-striped table-bordered table-hover">
									<tr>
										<th>会员手机号</th>
										<th>姓名</th>
										<th>小票号</th>
										<th>消费金额</th>
										<th>支付方式</th>
										<th>店铺名称</th>
										<th>操作人</th>
										<th>消费时间</th>
										<th>审核</th>
									</tr>
									<c:forEach items="${consumes}" var="consume" varStatus="status">
										<tr <c:if test="${status.count%2==0}">bgcolor="#d8e7f0"</c:if>
											<c:if test="${status.count%2!=0}">bgcolor="#ffffff"</c:if>>
											<td>${consume.memberMobile}</td>
											<td>${consume.memberName }</td>
											<td>${consume.smallBanks }</td>
											<td>${consume.money }</td>
											<td>
												<c:if test="${consume.type==0 }">现金</c:if>
												<c:if test="${consume.type==1 }">余额</c:if>
											</td>
											<td>${consume.shopName}</td>
											<td>${consume.userName}</td>
											<td>${fn:substring(consume.createTime, 0, fn:indexOf(consume.createTime, '.0')) }</td>
											<td>
												<c:choose>
													<c:when test="${consume.examineFlag == 0 }">
														<a id="exeExamine" class="btn btn-xs btn-primary radius"
															href="logconsumeexamineaction!manualExamine?consume.id=${consume.id }">
															批准通过
														</a>
													</c:when>
													<c:when test="${consume.examineFlag == 1 }">
														您已审核
													</c:when>
												</c:choose>
											</td>
										</tr>
									</c:forEach>
								</table>
								<input type="hidden" id="currentIndex" value="${index }">
								<input type="hidden" id="lastIndex" value="${page }">
								<div class="row" id="page">
									<ul class="pagination">
										<li><a href="javascript:void(0);" id="firstPage">首页</a></li>
										<li class="prev"><a href="javascript:void(0);"
											id="previousPage"> <i class="icon-double-angle-left"></i>
										</a>
										</li>
										<li><a href="javascript:void(0)">${index }</a></li>
										<li><a href="javascript:void(0);" id="nextPage"> <i
												class="icon-double-angle-right"></i> </a>
										</li>
										<li><a href="javascript:void(0);" id="lastPage">末页</a></li>
										<li><a href="javascript:void(0)">共${page}页</a></li>
									</ul>
								</div>
								<!-- PAGE CONTENT ENDS -->
							</div>
							<!-- /.col -->
						</div>
						<!-- /.row -->
					</div>
					<!-- /.page-content -->
				</div>
				<!-- /.main-content -->
			</div>
			<!-- /.main-container-inner -->
			<a href="#" id="btn-scroll-up"
				class="btn-scroll-up btn btn-sm btn-inverse"
				style="position:fixed;bottom:0;"> <i
				class="icon-double-angle-up icon-only bigger-110"></i> </a>
		</div>
		<!-- /.main-container -->
		<div class="push"></div>
	</div>
	<c:import url="/collect/down.jsp"></c:import>
	<!-- 弹出框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content radius">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">操作提示</h4>
				</div>
				<div class="modal-body">
					<p>确定批准通过此记录吗？</p>
				</div>
				<div class="modal-footer radius">
					<a id="confirm" class="btn btn-primary btn-sm radius">确定</a>
					<button type="button" class="btn btn-sm btn-default radius"
						data-dismiss="modal">取消</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>
</body>

<script type="text/javascript">
	$(document).ready(function() {
		// 防回收
		$('.xiaofeishenhe > ul').show();
		$('.xiaofeishenhe > ul > li > a').eq(0).css("color", "red");
		
		$("#oneMemberBtn").click(function() {
			watchEnterpriseConsume(1);
		});

		$("#eaStore").change(function() {
			watchEnterpriseConsume(1);
		});

		$("#examineFlag").change(function() {
			watchEnterpriseConsume(1);
		});
		
		// 第一页
		$("#firstPage").click(function() {
			watchEnterpriseConsume(1);
		});

		// 上一页
		$("#previousPage").click(function() {
			var index = $("#currentIndex").val();
			watchEnterpriseConsume(parseInt(index) - parseInt(1));
		});

		// 下一页
		$("#nextPage").click(function() {
			var index = $("#currentIndex").val();
			watchEnterpriseConsume(parseInt(index) + parseInt(1));
		});

		// 最末页
		$("#lastPage").click(function() {
			var index = $("#lastIndex").val();
			watchEnterpriseConsume(index);
		});

		function watchEnterpriseConsume(index) {
			var beginTime = $("#beginTime").val();
			var endTime = $("#endTime").val();
			
			if (beginTime.length != 0 && endTime.length != 0) {
				var start = new Date(beginTime.replace("-", "/").replace("-", "/"));  
			    var end = new Date(endTime.replace("-", "/").replace("-", "/"));
			    if (start >= end) {
					alert("结束时间必须大于开始时间！");
					return false;
				}
			}
			
			var minMoney = $("#minMoney").val();
			var maxMoney = $("#maxMoney").val();
			
			if (isNaN(minMoney)) {
				alert("最小金额必须为数字！");
				return false;
			}
			
			if (isNaN(maxMoney)) {
				alert("最大金额必须为数字！");
				return false;
			}
			
			if (minMoney.length != 0 && maxMoney.length != 0) {
				if (parseFloat(minMoney) >= parseFloat(maxMoney)) {
					alert("最大金额必须大于最小金额！");
					return false;
				}
			}
			
			var url = "logconsumeexamineaction!watchManualExamine?index=" + index;
			url += "&consume.memberMobile=" + $("#mobile").val();
			url += "&consume.shopId=" + $("#eaStore").val();
			url += "&consume.examineFlag=" + $("#examineFlag").val();
			url += "&consume.smallBanks=" + $("#smallBanks").val();
			url += "&consume.beginTime=" + beginTime;
			url += "&consume.endTime=" + endTime;
			url += "&consume.minMoney=" + $("#minMoney").val();
			url += "&consume.maxMoney=" + $("#maxMoney").val();
			
			window.location.href = url;
		}
		
		//提示框中确定按钮绑定单条消费记录审核事件
		$("a#exeExamine").click(function() {
			var href = $(this).attr("href");
			href += "&consumeWithCondition.memberMobile=" + $("#mobile").val();
			href += "&consumeWithCondition.shopId=" + $("#eaStore").val();
			href += "&consumeWithCondition.examineFlag=" + $("#examineFlag").val();
			href += "&consumeWithCondition.smallBanks=" + $("#smallBanks").val();
			href += "&consumeWithCondition.beginTime=" + $("#beginTime").val();
			href += "&consumeWithCondition.endTime=" + $("#endTime").val();
			href += "&consumeWithCondition.minMoney=" + $("#minMoney").val();
			href += "&consumeWithCondition.maxMoney=" + $("#maxMoney").val();
			href += "&index=" + $("#currentIndex").val();
			$("#myModal").modal('show');
			$("a#confirm").attr("href", href);
			return false;
		});
		
		//提示框中确定按钮绑定一键审核事件
		$("input#verifyConsumeBtn").click(function() {
			var verifyConsumeMoney = $("#verifyConsume").val();
			if (verifyConsumeMoney.length != 0) {
				if (isNaN(verifyConsumeMoney)) {
					$("#verifyConsume").val("");
					$("#verifyConsume").focus();
					alert("对账金额必须是数字！");
					return false;
				}
				
				// 进行对账验证
				$.ajax({
					url : "logconsumeexamineaction!verifyConsumeLog",
					type : "post",
					data : {
						"consume.verifyMoney" : verifyConsumeMoney,
						"consume.shopId" : $("#eaStore").val()
					},
					datatype : "json",
					success : function(data) {
						var d = $.parseJSON(data);
						if (d != null) {
							if (d.temp == 'ok') { // 验证通过
								if (confirm("对账金额验证通过，确认进行一键审核？")) {
									var url = "logconsumeexamineaction!executeClickExamine";
									url += "?consume.shopId=" + $("#eaStore").val();
									url += "&consumeWithCondition.memberMobile=" + $("#mobile").val();
									url += "&consumeWithCondition.shopId=" + $("#eaStore").val();
									url += "&consumeWithCondition.examineFlag=" + $("#examineFlag").val();
									url += "&consumeWithCondition.smallBanks=" + $("#smallBanks").val();
									url += "&consumeWithCondition.beginTime=" + $("#beginTime").val();
									url += "&consumeWithCondition.endTime=" + $("#endTime").val();
									url += "&consumeWithCondition.minMoney=" + $("#minMoney").val();
									url += "&consumeWithCondition.maxMoney=" + $("#maxMoney").val();
									url += "&index=" + $("#currentIndex").val();
									window.location.href = url;
								}
							}else{
								alert(d.temp);
							}
							
						} else {
							alert("对账金额验证失败！");
						}
					},
					error : function(request) {
						alert("Connection error");
					}
				});
			}else {
				if (confirm("您没有填写验证金额，是否不做验证，继续一键审核？")) {
					var url = "logconsumeexamineaction!executeClickExamine";
					url += "?consume.shopId=" + $("#eaStore").val();
					url += "&consumeWithCondition.memberMobile=" + $("#mobile").val();
					url += "&consumeWithCondition.shopId=" + $("#eaStore").val();
					url += "&consumeWithCondition.examineFlag=" + $("#examineFlag").val();
					url += "&consumeWithCondition.smallBanks=" + $("#smallBanks").val();
					url += "&consumeWithCondition.beginTime=" + $("#beginTime").val();
					url += "&consumeWithCondition.endTime=" + $("#endTime").val();
					url += "&consumeWithCondition.minMoney=" + $("#minMoney").val();
					url += "&consumeWithCondition.maxMoney=" + $("#maxMoney").val();
					url += "&index=" + $("#currentIndex").val();
					window.location.href = url;
				}
			}
			return false;
		});
		
	});
</script>
</html>
